deferred class IUP_WIDGET_FOCUS
-- Command to handle the focus.

inherit
	IUP_WIDGET_INTERNALS
	
insert
	IUP_INTERFACE

feature {ANY}

	set_focus: IUP_WIDGET
		-- Sets the interface element that will receive the keyboard focus, 
		-- i.e., the element that will receive keyboard events.
		--
		-- Returns: the identifier of the interface element that previously 
		-- had the keyboard focus.
		local
			p: POINTER
		do
			p := int_set_focus(widget)

			if p.is_not_null then
				Result := iup_open.get_widget_for_object(p)
			end
		end

	next_field: IUP_WIDGET
		-- Shifts the focus to the next element that can have the focus. It is 
		-- relative to the current element and does not depend on the element 
		-- currently with the focus.
		--
		-- It will search for the next element first in the children, then in the 
		-- brothers, then in the uncles and their children, and so on.
		--
		-- This sequence is not the same sequence used by the Tab key, which is 
		-- dependent on the native system.
		--
		-- Returns: the element that received the focus or Void if not found.
		local
			p: POINTER
		do
			p := int_next_field(widget)

			if p.is_not_null then
				Result := iup_open.get_widget_for_object(p)
			end
		end

	previous_field: IUP_WIDGET
		-- Shifts the focus to the previous element that can have the focus. It 
		-- is relative to the current element and does not depend on the element 
		-- currently with the focus.
		--
		-- Returns: the element that received the focus or Void if not found.
		local
			p: POINTER
		do
			p := int_previous_field(widget)

			if p.is_not_null then
				Result := iup_open.get_widget_for_object(p)
			end
		end

feature {}

	-- Internals

	int_set_focus (wgt: POINTER): POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupSetFocus"
         }"
      end

	int_next_field (wgt: POINTER): POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupNextField"
         }"
      end

	int_previous_field (wgt: POINTER): POINTER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupPreviousField"
         }"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
